package com.lankystar.logistucs.spring.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lankystar.logistucs.spring.dao.ICargoDao;
import com.lankystar.logistucs.spring.dao.ICompanyDao;
import com.lankystar.logistucs.spring.entity.Address;
import com.lankystar.logistucs.spring.entity.Cargo;
import com.lankystar.logistucs.spring.entity.Company;
import com.lankystar.logistucs.spring.service.CompanyService;

@Service
public class CompanyServiceImpl implements CompanyService{

	@Autowired
	private ICompanyDao companyDao;
	@Autowired
	private ICargoDao cargoDao;
	
	public Company queryCompanyById(int companyId){
		Company company = companyDao.selectCompanyById(companyId);
		return company;
	}
	
	@Override
	public void addCompany(Company record) {
		record.setCreateTime(new Date().getTime());
		record.setRemove(0);
		companyDao.add(record);
	}
	
	@Override
	public void updateCompany(Company record,int userId) {
		
	}

	@Override
	public List<Map<String, Object>> queryCargoAndAddresslist() {
		List<Map<String, Object>> maplist = new ArrayList<>();
		List<Object[]> cargolist = cargoDao.selectCargoAndAddresslist();
		for (Object[] objects : cargolist) {
			Cargo cargo = (Cargo) objects[0];
			Address address = (Address) objects[2];
			Map<String, Object> map = new HashMap<>();
			map.put("cargoId", cargo.getCargoId());
			map.put("count", cargo.getCount());
			map.put("heavy", cargo.getHeavy());
			map.put("pointOrderNu", cargo.getPointOrderNu());
			map.put("totalOrderNu", cargo.getTotalOrderNu());
			map.put("uploadPdf", cargo.getUploadPdf());
			map.put("detailed", address.getDetailed());
			maplist.add(map);
		}
		return maplist;
	}

	@Override
	public List<Map<String, Object>> queryLastOrderAndAddresslist() {
		List<Map<String, Object>> maplist = new ArrayList<>();
		List<Object[]> cargolist = cargoDao.selectLastOrderAndAddresslist();
		for (Object[] objects : cargolist) {
			Cargo cargo = (Cargo) objects[0];
			Address address = (Address) objects[2];
			Map<String, Object> map = new HashMap<>();
			map.put("cargoId", cargo.getCargoId());
			map.put("count", cargo.getCount());
			map.put("heavy", cargo.getHeavy());
			map.put("pointOrderNu", cargo.getPointOrderNu());
			map.put("totalOrderNu", cargo.getTotalOrderNu());
			map.put("uploadPdf", cargo.getUploadPdf());
			map.put("detailed", address.getDetailed());
			maplist.add(map);
		}
		return maplist;
	}
	@Override
	public List<Map<String, Object>> queryCompanyFeetlist() {
		/**
		 * 运输队
		 */
		List<Map<String, Object>> maplist = new ArrayList<>();
		List<Company> fleetlist = companyDao.selectCompanyFleetlist();
		for (Company cp : fleetlist) {
			Map<String, Object> map = new HashMap<>();
			map.put("companyId", cp.getCompanyId());
			map.put("companyName", cp.getCompanyName());
			maplist.add(map);
		}
		return maplist;
	}

	@Override
	public List<Map<String, Object>> queryCompanyBrokerlist() {
		List<Map<String, Object>> maplist = new ArrayList<>();
		/**
		 * 像上海报关行一样的公司
		 */
		List<Company> brokerlist = companyDao.selectCompanyBrokerlist();
		for (Company cp : brokerlist) {
			Map<String, Object> map = new HashMap<>();
			map.put("companyId", cp.getCompanyId());
			map.put("companyName", cp.getCompanyName());
			maplist.add(map);
		}
		return maplist;
	}
	
	

}
